package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.pojo.Competitions.Competitions;
import com.example.demo.pojo.Competitions.UserCompetitionDetail;
import com.example.demo.pojo.Competitions.VipCompetitionDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CompetitionMapper extends BaseMapper<Competitions> {

    @Select("SELECT " +
            "c.competition_id, " +
            "c.name AS competitionName, " +
            "c.description AS competitionDescription, " +
            "c.creat_user_name, " +
            "c.rule_description, " +
            "c.start_date, " +
            "c.end_date, " +
            "c.entry_conditions, " +
            "c.status AS competitionStatus, " +
            "uc.user_competition_id, " +
            "uc.user_id, " +
            "uc.real_name, " +
            "uc.status AS participationStatus " +
            "FROM user_competitions uc " +
            "JOIN competitions c ON uc.competition_id = c.competition_id " +
            "WHERE uc.user_id = #{userId}")
    List<UserCompetitionDetail> getCompetitionsByUserId(Integer userId);

    @Select("SELECT " +
            "cp.id AS passcodeId, " +
            "cp.competition_id AS competitionId, " +
            "cp.passcode, " +
            "cp.create_time AS createTime, " +
            "c.vip_id AS vipId, " +
            "c.name AS competitionName, " +
            "c.description AS competitionDescription, " +
            "c.creat_user_name AS creatUserName, " +
            "c.rule_description AS ruleDescription, " +
            "c.start_date AS startDate, " +
            "c.end_date AS endDate, " +
            "c.entry_conditions AS entryConditions, " +
            "c.status AS competitionStatus " +
            "FROM competition_passcode cp " +
            "JOIN competitions c ON cp.competition_id = c.competition_id " +
            "WHERE c.vip_id = #{userId}")
    List<VipCompetitionDetail> getCreatCompetitionByUserId(@Param("userId") Integer userId);
}
